﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DELVE_GAME.ViewStructure
{
    class UpgradeMenuComposite : ViewComponent
    {
        List<Button> buttons;
        public UpgradeMenuComposite()
        {
            this.width = 384;
            this.height = 64;
            buttons = new List<Button>();
        }

        public void add(Button b)
        {
            buttons.Add(b);
        }

        public override void mouseOver(int x, int y)
        {
            foreach (ViewComponent b in buttons)
            {
                b.mouseOver(x, y);
            }
        }

        public override void mousePressed(int x, int y)
        {
            if (checkCollision(x, y))
            {
                foreach (ViewComponent b in buttons)
                {
                    b.mousePressed(x, y);
                }
            }
            else
            {
                //List<int> temp = new List<int>{ 0, 1, 2, 3, 4, 5 };
                //setUpgradesActive(temp);
                this.visible = false;
            }
        }

        public override void mouseReleased(int x, int y)
        {
            foreach (ViewComponent b in buttons)
            {
                b.mouseReleased(x, y);
            }
        }

        public override void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
        {
            foreach (ViewComponent b in buttons)
            {
                b.draw(sb);
            }
        }

        public override void setLocation(int x, int y)
        {
            this.x = x;
            this.y = y;
            foreach (ViewComponent b in buttons)
            {
                b.setOffset(x,y);
            }
        }
        public override bool checkCollision(int x, int y)
        {
            return (x >= this.x + offsetX && y >= this.y + offsetY && x < this.x + offsetX + this.width && y < this.y + offsetY + this.height);
        }

        internal void setUpgradesActive(List<int> availableUpgrades)
        {
            if (availableUpgrades != null)
            {
                for (int i = 0; i < buttons.Count; i++)
                {
                    if (availableUpgrades.Contains(i))
                    {
                        buttons[i].setActive(true);
                    }
                    else
                    {
                        buttons[i].setActive(false);
                    }
                }
            }
        }
    }
}
